package com.yimi.yinhepda.views.main.my_module

import android.app.Activity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import cn.uce.pda.R
import com.pda.uce.commom.util.LogHelper
import com.pda.uce.commom.util.OffLineCheckTimeModule
import com.pda.uce.commom.util.Sp_net_Util
import com.uce.pda.module.MailModule
import kotlinx.android.synthetic.main.activity_power.*
import java.text.SimpleDateFormat
import java.util.*

class PowerActivity :Activity(), View.OnClickListener {
    override fun onClick(p0: View) {
        when (p0.id) {
            R.id.button4 -> { //开启日志打印功能
                Sp_net_Util.getInstance().putBoolean("logPower",true)
                LogHelper.LOG_LEVEL = LogHelper.VERBOSE;
            }
            R.id.button5 -> { //关闭日志打印功能
                Sp_net_Util.getInstance().putBoolean("logPower",false)
                LogHelper.LOG_LEVEL = LogHelper.NOTHING;
            }
            R.id.button6 -> { //打印到文件
                Sp_net_Util.getInstance().putBoolean("logToFile",true)
            }
            R.id.button7 -> { //打印到控制台
                Sp_net_Util.getInstance().putBoolean("logToFile",false)
            }
            R.id.button8 -> { //发送日志文件
                MailModule(PowerActivity@ this).zipFolder(null)
            }
        }
    }


    override fun onContentChanged() {
        super.onContentChanged()
        var activityThis=PowerActivity@ this
        initView()
        button4.setOnClickListener(this)
        button5.setOnClickListener(this)
        button6.setOnClickListener(this)
        button7.setOnClickListener(this)
        button8.setOnClickListener(this)
        button10.setOnClickListener(object:View.OnClickListener{
            override fun onClick(v: View?) {
                MailModule(activityThis).sendErrorFile()
            }
        })
    }


    /*
    * 将时间戳转换为时间
    */
    fun stampToDate(s: Long): String {
        val res: String
        val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val date = Date(s)
        res = simpleDateFormat.format(date)
        return res
    }


    fun initView(){
        var textViewTime=findViewById<TextView>(cn.uce.pda.R.id.text_view_time)

        textViewTime.setText(stampToDate(OffLineCheckTimeModule.getInstance().serverTime))

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_power)
    }

}